let Performance = require('../../components/performance.js');
let pfmId = 1002;
let pfmId2 = 2001;
let app = getApp(),
  {
    $resHost,
    $host
  } = app.globalData,
  eventProxy = require('../Common/eventProxy.js'),
  $extConfig = xhs.getExtConfigSync(),
  {
    $config
  } = app.globalData,
  _ = require('../Common/underscore.js'),
  {
    subscribeMessage,
    initPay
  } = require('../Common/pay.js'),
  getShare = require('../Common/getShare.js');
Page({
  data: {
    isGou: false,
    isGous: false,
    isEdit: false,
    //个人资料h5修改   
    isUpdate: false,
    shareEmployeeId: '',
    shareUserId: '',
    wechatId: '',
    authWechatId: '',
    tabs: [],
    browsingList: [],
    followerList: [],
    tab: '',
    template: '',
    isShowModal: false,
    shareInfo: {},
    total: 0,
    isMore: true,
    page: 1,
    itemId: '',
    options: {},
    type: '1',
    orgId: '0',
    pageId: '0',
    vcardIcon: `${$resHost}/img/miniprogram/vcard/vcard-arrow2.gif`,
    noneVcard: `${$resHost}/img/miniprogram/home/747760402723170354.png`,
    myVcardIcon: `${$resHost}/img/miniprogram/vcard/icon1.png`,
    list: [],
    user: {},
    fetchFollowerList: [],
    isEmployee: false,
    cardListPage: 1,
    cardListTotal: 0,
    indicatorDots: false,
    vertical: true,
    autoplay: false,
    circular: true,
    previousMargin: 0,
    nextMargin: 0,
    duration: 500,
    meLock: false,
    indexLock: false,
    tweetLock: false,
    hrefToLock: false,
    orgId2: '',
    list2: [],
    renderData: {},
    renderData2: {},
    isisHrefTo: 0,
    //兼容装修 orgId  pageId
    showSupport: true,
    techSupportName: '',
    points: 0,
    coins: 0,
    memberLevel: '',
    templates: [],
    employeeWaitActivateFlag: false,
    topOrgId: ''
  },
  record: null,
  record1: null,
  onShow() {
    xhs.getStorage({
      key: 'isClose',
      success: res => {
        if (this.selectComponent("#me")) {
          this.selectComponent("#me").setNoAuthoriz();
        }
        xhs.removeStorage({
          key: 'isClose'
        });
      }
    });
    xhs.getStorage({
      key: 'isEdit',
      success: res => {
        if (this.selectComponent("#me")) {
          this.selectComponent("#me").updateUser();
        }
        xhs.removeStorage({
          key: 'isEdit'
        });
      }
    });
    this.selectComponent("#me").getRefresh();

    // finish接口只会上传第一次掉用的数据
    this.record.finish();
    this.record1.finish();

    // 自定义导航
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 4
      });
    }
  },
  getRefreshFn() {
    if (this.selectComponent("#me")) {
      setTimeout(() => {
        this.selectComponent("#me").getRefresh();
      }, 600);
    }
  },
  onLoad(options) {
    this.record = Performance.startRecord(pfmId);
    this.record1 = Performance.startRecord(pfmId2);
    if (this.selectComponent("#me")) {
      this.selectComponent("#me").getUser();
    }
    this.isEmployeeFn();
    initPay();
  },
  setAgreement(e) {
    if (e.currentTarget.dataset.i == '0') {
      this.setData({
        isGou: true
      });
    } else {
      this.setData({
        isGous: true
      });
    }
  },
  isEmployeeFn() {
    // 这里要时时激活员工 不能用缓存
    app.$getData('/user/employee/is-employee').then(data => {
      if (data.errCode == 0) {
        this.setData({
          isEmployee: data.data.isEmployee,
          points: data.data.userInfo.points || 0,
          coins: data.data.userInfo.coins || 0,
          memberLevel: data.data.userInfo.memberLevel || '',
          employeeWaitActivateFlag: data.data.employeeWaitActivateFlag,
          topOrgId: data.data.userInfo.topOrgId
        });
        xhs.setStorageSync('isEmployee', data.data);
        xhs.setStorageSync('employeeInfo', data.data.employeeInfo);
        xhs.setStorageSync('user', data.data.userInfo);
      } else {
        xhs.showToast({
          icon: 'none',
          title: data.errInfo
        });
      }
    });
  },
  toManage() {
    subscribeMessage([5, 1], {}, '', '您没有开启订阅消息, 将无法收到服务消息').then(() => {
      xhs.redirectTo({
        url: $extConfig.employeeIndex || $config.employeeIndex
      });
    });
  }
  // getVideoL(){
  //   wx.navigateTo({
  //     url: '/pages/Employee/videoList/videoListMy/index'
  //   })
  // }
});